//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_createdomusermenu.sqf"
#include "x_setup.sqf"

_start_key = 1;
_fnc_inc_num = {
	__INC(_start_key);
	_start_key
};

_is_para = ((vehicle player) isKindOf "BIS_Steerable_Parachute") || {(vehicle player) isKindOf "ParachuteBase"};

GVAR(DomUserMenu) = [
	["Domination", false],
	[localize "STR_DOM_MISSIONSTRING_304", [call _fnc_inc_num], "", -5, [["expression", "0 call d_fnc_DomCommandingMenuExec"]], "1", "1"],
	["-", [0], "", -1, [["expression", ""]], "1", "1"]
];

_hxhx = __pGetVar(GVAR(p_isadmin));
if ((!isNil "_hxhx" && {_hxhx}) || {((GVAR(player_can_call_arti) > 0 || {(if (!isnil "mp_rights_fnc_hasRoles") then {([] call mp_rights_fnc_isMember)} else {false})}) && {GVAR(areArtyVecsAvailable)} && {!visibleMap} && {!_is_para})}) then {
	// Tyrghen
	if (!isnil "mp_rights_fnc_hasRoles") then {
		if ([] call mp_rights_fnc_isRecruit) then {
			GVAR(DomUserMenu) set [count GVAR(DomUserMenu),
				[localize "STR_DOM_MISSIONSTRING_153", [call _fnc_inc_num], "", -5, [["expression", "1 call d_fnc_DomCommandingMenuExec"]], "1", "1"]
			];
		};
	} else {
		GVAR(DomUserMenu) set [count GVAR(DomUserMenu),
			[localize "STR_DOM_MISSIONSTRING_153", [call _fnc_inc_num], "", -5, [["expression", "1 call d_fnc_DomCommandingMenuExec"]], "1", "1"]
		];
	};
};

GVAR(DomUserMenu) set [count GVAR(DomUserMenu), ["-", [0], "", -1, [["expression", ""]], "1", "1"]];

_hxhx = __pGetVar(GVAR(p_isadmin));
if ((!isNil "_hxhx" && {_hxhx}) || {((GVAR(player_can_call_drop) > 0  || {(if (!isnil "mp_rights_fnc_hasRoles") then {([] call mp_rights_fnc_isRecruit)} else {false})}) && {!visibleMap} && {!_is_para})}) then {
	GVAR(DomUserMenu) set [count GVAR(DomUserMenu),
		[localize "STR_DOM_MISSIONSTRING_230", [call _fnc_inc_num], "", -5, [["expression", "2 call d_fnc_DomCommandingMenuExec"]], "1", "1"]
	];
};

GVAR(DomUserMenu) set [count GVAR(DomUserMenu), ["-", [0], "", -1, [["expression", ""]], "1", "1"]];

if (GVAR(player_can_build_trench) && {!visibleMap} && {vehicle player == player} && {isNull __pGetVar(GVAR(trench))}) then {
	GVAR(DomUserMenu) set [count GVAR(DomUserMenu),
		[localize "STR_DOM_MISSIONSTRING_303", [call _fnc_inc_num], "", -5, [["expression", "3 call d_fnc_DomCommandingMenuExec"]], "1", "1"]
	];
};

GVAR(DomUserMenu) set [count GVAR(DomUserMenu), ["-", [0], "", -1, [["expression", ""]], "1", "1"]];

if (GVAR(player_can_build_mgnest) && {!visibleMap} && {vehicle player == player} && {count __pGetVar(GVAR(mgnest_pos)) == 0}) then {
	GVAR(DomUserMenu) set [count GVAR(DomUserMenu),
		[localize "STR_DOM_MISSIONSTRING_306", [call _fnc_inc_num], "", -5, [["expression", "4 call d_fnc_DomCommandingMenuExec"]], "1", "1"]
	];
};

/*
TODO No Mash tents in A3
if (GVAR(player_is_medic) && {vehicle player == player} && {count __pGetVar(GVAR(medtent)) == 0}) then {
	GVAR(DomUserMenu) set [count GVAR(DomUserMenu),
		[localize "STR_DOM_MISSIONSTRING_305", [call _fnc_inc_num], "", -5, [["expression", "5 call d_fnc_DomCommandingMenuExec"]], "1", "1"]
	];
};
*/

/*
TODO No Farps in A3
if (GVAR(eng_can_repfuel) && {vehicle player == player} && {count __pGetVar(GVAR(farp_pos)) == 0}) then {
	GVAR(DomUserMenu) set [count GVAR(DomUserMenu),
		[localize "STR_DOM_MISSIONSTRING_307", [call _fnc_inc_num], "", -5, [["expression", "6 call d_fnc_DomCommandingMenuExec"]], "1", "1"]
	];
};
*/

GVAR(DomUserMenu) set [count GVAR(DomUserMenu), ["-", [0], "", -1, [["expression", ""]], "1", "1"]];

_hxhx = __pGetVar(GVAR(p_isadmin));
if (!isNil "_hxhx" && {_hxhx} && {!visibleMap}) then {
	GVAR(DomUserMenu) set [count GVAR(DomUserMenu),
		[localize "STR_DOM_MISSIONSTRING_1420", [call _fnc_inc_num], "", -5, [["expression", "7 call d_fnc_DomCommandingMenuExec"]], "1", "1"]
	];
};

_clattached = player getVariable [QGVAR(p_clattached), ""];
__TRACE_1("","_clattached");
if (_clattached == "") then {
	_chemar = call FUNC(haschemlight);
	__TRACE_1("","_chemar");
	if (count _chemar > 0) then {
		GVAR(DomUserMenu) set [count GVAR(DomUserMenu), ["-", [0], "", -1, [["expression", ""]], "1", "1"]];
		
		{
			_strnum = switch (_x) do {
				case "Chemlight_green": {"15"};
				case "Chemlight_red": {"16"};
				case "Chemlight_yellow": {"17"};
				case "Chemlight_blue": {"18"};
				default {""};
			};
			if (_strnum != "") then {
				GVAR(DomUserMenu) set [count GVAR(DomUserMenu),
					[format [localize "STR_DOM_MISSIONSTRING_1506", getText(configFile/"CfgMagazines"/_x/"displayName")], [call _fnc_inc_num], "", -5, [["expression", _strnum + " call d_fnc_DomCommandingMenuExec"]], "1", "1"]
				];
			};
		} forEach _chemar;
	};
} else {
	if (_clattached != "") then {
		GVAR(DomUserMenu) set [count GVAR(DomUserMenu), ["-", [0], "", -1, [["expression", ""]], "1", "1"]];
		
		GVAR(DomUserMenu) set [count GVAR(DomUserMenu),
			[localize "STR_DOM_MISSIONSTRING_1505", [call _fnc_inc_num], "", -5, [["expression", "20 call d_fnc_DomCommandingMenuExec"]], "1", "1"]
		];
	};
};

//TYRGHEN - Generic method to add menus to the Domination Menu
if (!isnil "mso_fnc_dominationMenuEntries") then {
	GVAR(DomUserMenu) set [count GVAR(DomUserMenu), ["-", [0], "", -1, [["expression", ""]], "1", "1"]];
	{ 
		GVAR(DomUserMenu) set [count GVAR(DomUserMenu),
			[(_x select 0), [call _fnc_inc_num], "", -5, [["expression", (_x select 1)]], "1", "1"]
		];
	} foreach (0 call mso_fnc_dominationMenuEntries);
};